Imports System.Configuration.ConfigurationManager
Imports System.Net.Mail
Imports System.Net


Namespace Workflow


    Public Class CConfig

        'Strings
        Public Shared ReadOnly Property SmtpServer() As String
            Get
                Return Config("SmtpServer")
            End Get
        End Property

#Region "Gmail"
        Private Shared ReadOnly Property GmailUser As String
            Get
                Return Config("GmailUser")
            End Get
        End Property
        Private Shared ReadOnly Property GmailPassword As String
            Get
                Return Config("GmailPassword")
            End Get
        End Property

        Private Shared GmailMailPort1 As Integer = 587
        Private Shared GmailMailPort2 As Integer = 465
        Public Shared ReadOnly Property GmailOnPort1 As SmtpClient
            Get
                Return GmailOnPort(False)
            End Get
        End Property
        Public Shared ReadOnly Property GmailOnPort2 As SmtpClient
            Get
                Return GmailOnPort(True)
            End Get
        End Property
        Protected Shared ReadOnly Property GmailOnPort(two As Boolean) As SmtpClient
            Get
                Dim temp As New SmtpClient("smtp.gmail.com", IIf(two, GmailMailPort2, GmailMailPort1)) 'Fresh instance: much slower, but safer
                temp.EnableSsl = True
                temp.UseDefaultCredentials = False
                temp.Credentials = New NetworkCredential(GmailUser, GmailPassword)
                'temp.Timeout = 10 * 60 * 1000 ' increase from 100 to 600 seconds (10mins)
                Return temp
            End Get
        End Property
#End Region

        'Integers
        Public Shared ReadOnly Property CategoryOther() As Integer
            Get
                Return Config("CategoryOther", 3)
            End Get
        End Property

        Public Shared ReadOnly Property StatusNotStarted() As Integer
            Get
                Return Config("StatusNotStarted", 1)
            End Get
        End Property
        Public Shared ReadOnly Property StatusInProgress() As Integer
            Get
                Return Config("StatusInProgress", 6)
            End Get
        End Property
        Public Shared ReadOnly Property StatusComplete() As Integer
            Get
                Return Config("StatusComplete", 7)
            End Get
        End Property

        Public Shared ReadOnly Property PriorityHigh() As Integer
            Get
                Return Config("PriorityHigh", 2)
            End Get
        End Property
        Public Shared ReadOnly Property PriorityMedium() As Integer
            Get
                Return Config("PriorityMedium", 3)
            End Get
        End Property
        Public Shared ReadOnly Property PriorityLow() As Integer
            Get
                Return Config("PriorityLow", 4)
            End Get
        End Property

        'Private
        Private Shared Function Config(ByVal key As String, Optional ByVal defaultValue As String = "") As String
            Dim s As String = AppSettings(key)
            If Len(s) = 0 Then Return defaultValue
            Return s
        End Function
    End Class

End Namespace
